package itheima02;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author xxx
 * @date 2020/12/24 8:04
 * @description
 */
public class Test {
    public static void main(String[] args) {
         //通过Person录入对应的多条消息放入list集合，再通过Comparator接口的重写方法compare进行排列，最后转化为lambda表达式
        List<Person>list=new ArrayList();

        list.add(new Person("wkr",41));
        list.add(new Person("wwww",20));
        list.add(new Person("pp",30));

        Collections.addAll(list,new Person("111",12),
                                new Person("222",13),
                                new Person("333",14));
        //升序
        Collections.sort(list, new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                return  o1.getAge()-o2.getAge();
            }
        });
          System.out.println(list);

          //降序
        Collections.sort(list, new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                return o2.getAge()-o1.getAge();
            }
        });
        System.out.println(list);


        Collections.sort(list, (o1, o2) -> o1.getAge()-o2.getAge());
        System.out.println(list);


        Collections.sort(list, (o1, o2) -> o2.getAge()-o1.getAge());
        System.out.println(list);

    }
}
